#include "IOCPServer.h"
#include <thread>
#include <memory>

CIOCPServer* iocp;//Safe
int pNum = 0;

void AcceptT(IOCP_CLIENT* client)
{
	//WSABUF buffer;
	//buffer.buf = new char[1024 * 1024];
	//buffer.len = 1024 * 1024;
	//memset(buffer.buf, 'A', 1024 * 1024);
	//iocp->IOCP_SendData(client, buffer);
	//delete buffer.buf;
	__nop();
}

void Accept() {
	iocp->IOCP_AcceptThread(std::bind(&AcceptT, std::placeholders::_1));
}

void Recv() {
	iocp->IOCP_ProcessThread(NULL);
}

void GetDisconnectClient(IOCP_CLIENT* client) 
{
	pNum++;
	std::cout << pNum << "Leave" << std::endl;
}

int main() 
{
	iocp = new CIOCPServer();
	iocp->BindAndListen(21296);
	std::thread T1(Accept);
	std::thread T2(Recv);
	//std::thread T3(Recv);
	//std::thread T4(Recv);
	//std::thread T5(Recv);

	iocp->IOCP_SetDisconnectSignal(std::bind(&GetDisconnectClient, std::placeholders::_1));


	getchar();
	delete iocp;
	T1.join();
	T2.join();
	return 0;
}